#pragma once

#include <vector>

template <class T>
class DynamicArray2d
{
public:
	DynamicArray2d(int rows, int columns);

	T& at(int row, int column);
	const T& at(int row, int column) const;

	T* data();
	const T* data() const;

	int rows() const;
	int columns() const;

private:
	std::vector<T> data_;
	int rows_;
	int columns_;
};

template <class T>
inline int DynamicArray2d<T>::columns() const
{
	return columns_;
}

template <class T>
inline int DynamicArray2d<T>::rows() const
{
	return rows_;
}

template <class T>
inline T& DynamicArray2d<T>::at(int row, int column)
{
	return data_[row*columns_+column];
}

template <class T>
inline const T& DynamicArray2d<T>::at(int row, int column) const
{
	return data_[row*columns_+column];
}

template <class T>
inline DynamicArray2d<T>::DynamicArray2d(int rows, int columns)
: data_(rows*columns)
, rows_(rows)
, columns_(columns)
{
}

template <class T>
inline T* DynamicArray2d<T>::data()
{
	return &data_[0];
}

template <class T>
inline const T* DynamicArray2d<T>::data() const
{
	return &data_[0];
}

